﻿using RabbitMQ.Client;

namespace Rabbit.Common
{
    public class RabbitMQHelper
    {
        //public static async Task<IConnection> GetConnect(){
        //    //连接工厂
        //    var fac = new ConnectionFactory() { 
        //        HostName = "192.168.31.7",//IP
        //        Port=5672,//端口
        //        UserName="sqf",
        //        Password="8527391sqf",
        //        VirtualHost="/",
        //    };
        //    return await fac.CreateConnectionAsync();
        //}

        /// <summary>
        /// 获取连接
        /// </summary>
        /// <returns></returns>
        public static IConnection GetConnect()
        {
            //连接工厂
            var fac = new ConnectionFactory()
            {
                HostName = "192.168.31.128",//IP
                Port = 5671,//端口5672
                UserName = "sqf",
                Password = "8527391sqf",
                VirtualHost = "/"
            };

            //300个服务器没有做负载均衡 都要写在这里
            //IList<AmqpTcpEndpoint>list = new List<AmqpTcpEndpoint>();
            //list.Add(new AmqpTcpEndpoint { HostName= "192.168.31.106", Port=5672 });
            //list.Add(new AmqpTcpEndpoint { HostName = "192.168.31.165", Port = 5672 });

            return fac.CreateConnection();//list
        }

    }
}
